package com.jie.component.id.config;

import com.jie.common.util.LogUtil;
import com.jie.component.id.toolkit.SnowflakeIdGenerator;
import com.jie.component.id.toolkit.WorkAndDataCenterIdHandler;
import com.jie.component.id.toolkit.WorkDataCenterId;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;

public class IdGeneratorAutoConfig {

    @Bean
    public WorkAndDataCenterIdHandler workAndDataCenterIdHandler(StringRedisTemplate stringRedisTemplate) {
        LogUtil.autoConfigLog("WorkAndDataCenterIdHandler");
        return new WorkAndDataCenterIdHandler(stringRedisTemplate);
    }

    @Bean
    public WorkDataCenterId workDataCenterId(WorkAndDataCenterIdHandler workAndDataCenterIdHandler){
        LogUtil.autoConfigLog("WorkDataCenterId");
        return workAndDataCenterIdHandler.getWorkAndDataCenterId();
    }

    @Bean
    public SnowflakeIdGenerator snowflakeIdGenerator(WorkDataCenterId workDataCenterId) {
        LogUtil.autoConfigLog("SnowflakeIdGenerator");
        return new SnowflakeIdGenerator(workDataCenterId);
    }
}